//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class LovRepository : BaseRepository, ILovRepository
    {
        public LovRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Lov lov)
        {
            this.GetDbSet<Lov>().Add(lov);
            this.UnitOfWork.SaveChanges();
        }

        public Lov GetLov(Guid lovId)
        {
            return this.GetDbSet<Lov>()
                .Where(c => c.Id == lovId)
                .Single();
        }

        public void Update(Lov updatedLov)
        {
            this.GetDbSet<Lov>().Attach(updatedLov);
            this.SetEntityState(updatedLov, updatedLov.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid lovId)
        {
            Lov ApplicationToDelete = this.GetLov(lovId);
            this.GetDbSet<Lov>().Remove(ApplicationToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Lov> Find()
        {
            return this.GetDbSet<Lov>();
        }

        public IQueryable<Lov> GetAll()
        {
            return this.GetDbSet<Lov>();
        }
    }
}
